<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="author" content="WD">





<title>Python爬取天气数据及可视化分析 | WD&#39;s blog</title>



    <link rel="icon" href="/favicon1.ico">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/js/script.js"></script>
    
    <script src="/js/tocbot.min.js"></script>
    
    <script src="/js/snow.js"></script>
    



    
    
        
    


<meta name="generator" content="Hexo 5.4.0"></head>
<body>
    <div class="wrapper">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo"><a href="/">WD&#39;s Blog</a></div>
            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
                <input id="switch_default" type="checkbox" class="switch_default">
                <label for="switch_default" class="toggleBtn"></label>
            </div>
        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/">WD&#39;s Blog</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
            </div>
        </div>
    </nav>

</header>
<script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>
        <div class="main">
            <div class="container">
    
    
        <div class="post-toc">
    <div class="tocbot-list">
    </div>
    <div class="tocbot-list-menu">
        <a class="tocbot-toc-expand" onclick="expand_toc()">Expand all</a>
        <a onclick="go_top()">Back to top</a>
        <a onclick="go_bottom()">Go to bottom</a>
    </div>
</div>

<script>
    document.ready(
        function () {
            tocbot.init({
                tocSelector: '.tocbot-list',
                contentSelector: '.post-content',
                headingSelector: 'h1, h2, h3, h4, h5',
                collapseDepth: 1,
                orderedList: false,
                scrollSmooth: true,
            })
        }
    )

    function expand_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 6,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "collapse_toc()");
        b.innerHTML = "Collapse all"
    }

    function collapse_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 1,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "expand_toc()");
        b.innerHTML = "Expand all"
    }

    function go_top() {
        window.scrollTo(0, 0);
    }

    function go_bottom() {
        window.scrollTo(0, document.body.scrollHeight);
    }

</script>
    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">Python爬取天气数据及可视化分析</h1>
            
                <div class="post-meta">
                    
                        Author: <a itemprop="author" rel="author" href="/about/">WD</a>
                     &nbsp;

                    
                        <span class="post-time">
                        Date: <a href="#">July 29, 2020&nbsp;&nbsp;10:48:23</a>
                        </span>
                     &nbsp;
                    
                        <span class="post-category">
                    Category:
                            
                                <a href="/categories/Python/">Python</a>
                            
                        </span>
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <br>
    <span id="busuanzi_container_site_pv">总阅读量:<a href="#"><span id="busuanzi_value_page_pv"></span></a>次</span>&nbsp;
    <span class="post-count">文章字数:<a href="#">6.8k</span></a>&nbsp;
     <span class="post-count">阅读时长:<a href="#">30</span>min</a>
                    
                </div>
            
        </header>

        <div class="post-content">
            <h2 id="说在前面"><a href="#说在前面" class="headerlink" title="说在前面"></a>说在前面</h2><ul>
<li>天气预报我们每天都会关注，我们可以根据未来的天气增减衣物、安排出行，每天的气温、风速风向、相对湿度、空气质量等成为关注的焦点。本次使用python中<code>requests</code>和<code>BeautifulSoup</code>库对中国天气网当天和未来14天的数据进行爬取，保存为csv文件，之后用<code>matplotlib、numpy、pandas</code>对数据进行可视化处理和分析，得到温湿度度变化曲线、空气质量图、风向雷达图等结果，为获得未来天气信息提供了有效方法。</li>
</ul>
<h2 id="1-数据获取"><a href="#1-数据获取" class="headerlink" title="1.数据获取"></a>1.数据获取</h2><h3 id="请求网站链接"><a href="#请求网站链接" class="headerlink" title="请求网站链接"></a>请求网站链接</h3><ul>
<li><p>首先查看中国天气网的网址：<a target="_blank" rel="noopener" href="http://www.weather.com.cn/weather/101280701.shtml">http://www.weather.com.cn/weather/101280701.shtml</a> 这里就访问本地的天气网址，如果想爬取不同的地区只需修改最后的101280701地区编号即可，前面的weather代表是7天的网页，weather1d代表当天，weather15d代表未来14天。这里就主要访问7天和14天的中国天气网。采用<code>requests.get()</code>方法，请求网页，如果成功访问，则得到的是网页的所有字符串文本。这就是请求过程。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">getHTMLtext</span>(<span class="params">url</span>):</span>     </span><br><span class="line">	<span class="string">&quot;&quot;&quot;请求获得网页内容&quot;&quot;&quot;</span></span><br><span class="line">	<span class="keyword">try</span>:         </span><br><span class="line">		r = requests.get(url, timeout = <span class="number">30</span>)         </span><br><span class="line">		r.raise_for_status()         </span><br><span class="line">		r.encoding = r.apparent_encoding         </span><br><span class="line">		<span class="built_in">print</span>(<span class="string">&quot;成功访问&quot;</span>)         </span><br><span class="line">		<span class="keyword">return</span> r.text     </span><br><span class="line">	<span class="keyword">except</span>:         </span><br><span class="line">		<span class="built_in">print</span>(<span class="string">&quot;访问错误&quot;</span>)         </span><br><span class="line">		<span class="keyword">return</span><span class="string">&quot; &quot;</span> </span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="提取有用信息"><a href="#提取有用信息" class="headerlink" title="提取有用信息"></a>提取有用信息</h3><ul>
<li>这里采用BeautifulSoup库对刚刚获取的字符串进行数据提取，首先对网页进行检查，找到需要获取数据的标签：</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/20200729104337713.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595987903947"></p>
<ul>
<li><p>可以发现7天的数据信息在div标签中并且id=”7d”，并且日期、天气、温度、风级等信息都在ul和li标签中，所以我们可以使用BeautifulSoup对获取的网页文本进行查找div标签id=”7d”，找出他包含的所有的ul和li标签，之后提取标签中相应的数据值，保存到对应列表中。这里要注意一个细节就是有时日期没有最高气温，对于没有数据的情况要进行判断和处理。另外对于一些数据保存的格式也要提前进行处理，比如温度后面的摄氏度符号，日期数字的提取，和风级文字的提取，这需要用到字符查找及字符串切片处理。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_content</span>(<span class="params">html</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;处理得到有用信息保存数据文件&quot;&quot;&quot;</span></span><br><span class="line">	final = []  							 <span class="comment"># 初始化一个列表保存数据</span></span><br><span class="line">	bs = BeautifulSoup(html, <span class="string">&quot;html.parser&quot;</span>)  <span class="comment"># 创建BeautifulSoup对象</span></span><br><span class="line">	body = bs.body</span><br><span class="line">	data = body.find(<span class="string">&#x27;div&#x27;</span>, &#123;<span class="string">&#x27;id&#x27;</span>: <span class="string">&#x27;7d&#x27;</span>&#125;)    <span class="comment"># 找到div标签且id = 7d</span></span><br><span class="line">	<span class="comment"># 下面爬取当天的数据</span></span><br><span class="line">	data2 = body.find_all(<span class="string">&#x27;div&#x27;</span>,&#123;<span class="string">&#x27;class&#x27;</span>:<span class="string">&#x27;left-div&#x27;</span>&#125;)</span><br><span class="line">	text = data2[<span class="number">2</span>].find(<span class="string">&#x27;script&#x27;</span>).string	 </span><br><span class="line">	text = text[text.index(<span class="string">&#x27;=&#x27;</span>)+<span class="number">1</span> :-<span class="number">2</span>]		 <span class="comment"># 移除改var data=将其变为json数据</span></span><br><span class="line">	jd = json.loads(text)</span><br><span class="line">	dayone = jd[<span class="string">&#x27;od&#x27;</span>][<span class="string">&#x27;od2&#x27;</span>]				 <span class="comment"># 找到当天的数据</span></span><br><span class="line">	final_day = []						     <span class="comment"># 存放当天的数据</span></span><br><span class="line">	count = <span class="number">0</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> dayone:</span><br><span class="line">		temp = []</span><br><span class="line">		<span class="keyword">if</span> count &lt;=<span class="number">23</span>:</span><br><span class="line">			temp.append(i[<span class="string">&#x27;od21&#x27;</span>])				 <span class="comment"># 添加时间</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od22&#x27;</span>])				 <span class="comment"># 添加当前时刻温度</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od24&#x27;</span>])				 <span class="comment"># 添加当前时刻风力方向</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od25&#x27;</span>])				 <span class="comment"># 添加当前时刻风级</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od26&#x27;</span>])				 <span class="comment"># 添加当前时刻降水量</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od27&#x27;</span>])				 <span class="comment"># 添加当前时刻相对湿度</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od28&#x27;</span>])				 <span class="comment"># 添加当前时刻控制质量</span></span><br><span class="line">			<span class="comment">#print(temp)</span></span><br><span class="line">			final_day.append(temp)</span><br><span class="line">		count = count +<span class="number">1</span></span><br><span class="line">	<span class="comment"># 下面爬取7天的数据	</span></span><br><span class="line">	ul = data.find(<span class="string">&#x27;ul&#x27;</span>)					 <span class="comment"># 找到所有的ul标签</span></span><br><span class="line">	li = ul.find_all(<span class="string">&#x27;li&#x27;</span>)					 <span class="comment"># 找到左右的li标签</span></span><br><span class="line">	i = <span class="number">0</span>  			<span class="comment"># 控制爬取的天数</span></span><br><span class="line">	<span class="keyword">for</span> day <span class="keyword">in</span> li:  						 	<span class="comment"># 遍历找到的每一个li</span></span><br><span class="line">	    <span class="keyword">if</span> i &lt; <span class="number">7</span> <span class="keyword">and</span> i &gt; <span class="number">0</span>:</span><br><span class="line">	        temp = []  						 	<span class="comment"># 临时存放每天的数据</span></span><br><span class="line">	        date = day.find(<span class="string">&#x27;h1&#x27;</span>).string  	 	<span class="comment"># 得到日期</span></span><br><span class="line">	        date = date[<span class="number">0</span>:date.index(<span class="string">&#x27;日&#x27;</span>)]  	<span class="comment"># 取出日期号</span></span><br><span class="line">	        temp.append(date)				        </span><br><span class="line">	        inf = day.find_all(<span class="string">&#x27;p&#x27;</span>)  		 	<span class="comment"># 找出li下面的p标签,提取第一个p标签的值，即天气</span></span><br><span class="line">	        temp.append(inf[<span class="number">0</span>].string)</span><br><span class="line"></span><br><span class="line">	        tem_low = inf[<span class="number">1</span>].find(<span class="string">&#x27;i&#x27;</span>).string  	<span class="comment"># 找到最低气温</span></span><br><span class="line"></span><br><span class="line">	        <span class="keyword">if</span> inf[<span class="number">1</span>].find(<span class="string">&#x27;span&#x27;</span>) <span class="keyword">is</span> <span class="literal">None</span>:  	<span class="comment"># 天气预报可能没有最高气温</span></span><br><span class="line">	            tem_high = <span class="literal">None</span></span><br><span class="line">	        <span class="keyword">else</span>:</span><br><span class="line">	            tem_high = inf[<span class="number">1</span>].find(<span class="string">&#x27;span&#x27;</span>).string  <span class="comment"># 找到最高气温</span></span><br><span class="line">	        temp.append(tem_low[:-<span class="number">1</span>])</span><br><span class="line">	        <span class="keyword">if</span> tem_high[-<span class="number">1</span>] == <span class="string">&#x27;℃&#x27;</span>:</span><br><span class="line">	        	temp.append(tem_high[:-<span class="number">1</span>])</span><br><span class="line">	        <span class="keyword">else</span>:</span><br><span class="line">	        	temp.append(tem_high)</span><br><span class="line">	        wind = inf[<span class="number">2</span>].find_all(<span class="string">&#x27;span&#x27;</span>)		<span class="comment"># 找到风向</span></span><br><span class="line">	        <span class="keyword">for</span> j <span class="keyword">in</span> wind:</span><br><span class="line">	        	temp.append(j[<span class="string">&#x27;title&#x27;</span>])</span><br><span class="line">	        wind_scale = inf[<span class="number">2</span>].find(<span class="string">&#x27;i&#x27;</span>).string <span class="comment"># 找到风级</span></span><br><span class="line">	        index1 = wind_scale.index(<span class="string">&#x27;级&#x27;</span>)</span><br><span class="line">	       	temp.append(<span class="built_in">int</span>(wind_scale[index1-<span class="number">1</span>:index1]))</span><br><span class="line">	        final.append(temp)</span><br><span class="line">	    i = i + <span class="number">1</span></span><br><span class="line">	<span class="keyword">return</span> final_day,final</span><br></pre></td></tr></table></figure>
</li>
<li><p>同样对于/weather15d：15天的信息，也做同样的处理，这里经过查看后发现他的15天网页中只有8-14天，前面的1-7天在/weather中，这里就分别访问两个网页将爬取得到的数据进行合并得到最终14天的数据。</p>
</li>
<li><p>前面是未来14天的数据爬取过程，对于当天24小时的天气信息数据，经过查找发现他是一个json数据，可以通过<code>json.loads()</code>方法获取当天的数据，进而对当天的天气信息进行提取。</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104321183.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595988307809"></p>
</li>
</ul>
<h3 id="保存csv文件"><a href="#保存csv文件" class="headerlink" title="保存csv文件"></a>保存csv文件</h3><ul>
<li><p>前面将爬取的数据添加到列表中，这里引入csv库，利用<code>f_csv.writerow(header)</code>和<code>f_csv.writerows(data)</code>方法，分别写入表头和每一行的数据，这里将1天和未来14天的数据分开存储，分别保存为<code>weather1.csv</code>和<code>weather14.csv</code>，下面是他们保存的表格图：</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104300647.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595988423843"></p>
<p><img src="https://img-blog.csdnimg.cn/20200729104348990.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595988476627"></p>
</li>
</ul>
<h2 id="2-可视化分析"><a href="#2-可视化分析" class="headerlink" title="2.可视化分析"></a>2.可视化分析</h2><h3 id="当天温度变化曲线图"><a href="#当天温度变化曲线图" class="headerlink" title="当天温度变化曲线图"></a>当天温度变化曲线图</h3><ul>
<li><p>采用matplotlib中plt.plot()方法绘制出一天24小时的温度变化曲线，并用plt.text()方法点出最高温和最低温，并画出平均温度线，下图为温度变化曲线图：(代码见附录)</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104413404.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595988661857"></p>
<blockquote>
<p>分析可以发现这一天最高温度为33℃，最低温度为28℃，并且平均温度在20.4℃左右，通过对时间分析，发现昼夜温差5℃，低温分布在凌晨，高温分布在中午到下午的时间段。</p>
</blockquote>
</li>
</ul>
<h3 id="当天相对湿度变化曲线图"><a href="#当天相对湿度变化曲线图" class="headerlink" title="当天相对湿度变化曲线图"></a>当天相对湿度变化曲线图</h3><ul>
<li><p>采用matplotlib中plt.plot()方法绘制出一天24小时的湿度变化曲线，并画出平均相对湿度线，下图为湿度变化曲线图：(代码见附录)</p>
<p><img src="https://img-blog.csdnimg.cn/2020072910450689.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595988799011"></p>
<blockquote>
<p>分析可以发现这一天最高相对湿度为86%，最低相对湿度为58℃，并且平均相对湿度在75%左右，通过对时间分析，清晨的湿度比较大，而下午至黄昏湿度较小。</p>
</blockquote>
</li>
</ul>
<h3 id="温湿度相关性分析图"><a href="#温湿度相关性分析图" class="headerlink" title="温湿度相关性分析图"></a>温湿度相关性分析图</h3><ul>
<li><p>经过前面两个图的分析我们可以感觉到温度和湿度之间是有关系的，为了更加清楚直观地感受这种关系，使用plt.scatter()方法将温度为横坐标、湿度为纵坐标，每个时刻的点在图中点出来，并且计算相关系数，下图为结果图：</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104528588.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595988946448"></p>
<blockquote>
<p>分析可以发现一天的温度和湿度具有强烈的相关性，他们呈负相关，这就说明他们时间是负相关关系，并且进一步分析，当温度较低时，空气中水分含量较多，湿度自然较高，而温度较高时，水分蒸发，空气就比较干燥，湿度较低，符合平时气候现象。</p>
</blockquote>
</li>
</ul>
<h3 id="空气质量指数柱状图"><a href="#空气质量指数柱状图" class="headerlink" title="空气质量指数柱状图"></a>空气质量指数柱状图</h3><ul>
<li><p>空气质量指数AQI是定量描述空气质量状况的指数，其数值越大说明空气污染状况越重，对人体健康的危害也就越大。一般将空气质量指数分为6个等级，等级越高说明污染越严重，下面使用plt.bar方法对一天24小时的空气质量进行了柱状图绘制，并且根据6个等级的不同，相应的柱状图的颜色也从浅到深，也表明污染逐步加重，更直观的显示污染情况，并且也将最高和最低的空气质量指数标出，用虚线画出平均的空气质量指数，下图是绘制结果图：</p>
<p><img src="https://img-blog.csdnimg.cn/2020072910454163.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595988905082"></p>
<blockquote>
<p>上面这张是南方珠海的控制质量图，可以看出空气质量指数最大也是在健康范围，说明珠海空气非常好，分析可以发现这一天最高空气质量指数达到了35，最低则只有14，并且平均在25左右，通过时间也可以发现，基本在清晨的时候是空气最好的时候（4-9点），在下午是空气污染最严重的时候，所以清晨一般可以去外面呼吸新鲜的空气，那时污染最小。</p>
</blockquote>
</li>
<li><p>而下面这个空气质量图是选取的北方的一个城市，可以看到这里的环境远远比不上珠海。</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104553184.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595989238572"></p>
</li>
</ul>
<h3 id="风向风级雷达图"><a href="#风向风级雷达图" class="headerlink" title="风向风级雷达图"></a>风向风级雷达图</h3><ul>
<li><p>统计一天的风力和风向，由于风力风向使用极坐标的方式展现较好，所以这里采用的是极坐标的方式展现一天的风力风向图，将圆分为8份，每一份代表一个风向，半径代表平均风力，并且随着风级增高，蓝色加深，最后结果如下所示：</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104605333.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595988928913"></p>
<blockquote>
<p>分析可以发现这一天西南风最多，平均风级达到了1.75级，东北风也有小部分1.0级，其余空白方向无来风。</p>
</blockquote>
</li>
</ul>
<h3 id="未来14天高低温变化曲线图"><a href="#未来14天高低温变化曲线图" class="headerlink" title="未来14天高低温变化曲线图"></a>未来14天高低温变化曲线图</h3><ul>
<li><p>统计未来14天的高低温度变化，并绘制出他们的变化曲线图，分别用虚线将他们的平均气温线绘制出来，最后结果如下所示：</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104619675.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595989497559"></p>
<blockquote>
<p>分析可以发现未来14天高温平均气温为30.5℃，温度还是比较高，但是未来的第8天有降温，需要做好降温准备，低温前面处于平稳趋势，等到第8天开始下降，伴随着高温也下降，整体温度下降，低温平均在27℃左右。</p>
</blockquote>
</li>
</ul>
<h3 id="未来14天风向风级雷达图"><a href="#未来14天风向风级雷达图" class="headerlink" title="未来14天风向风级雷达图"></a>未来14天风向风级雷达图</h3><ul>
<li><p>统计未来14天的风向和平均风力，并和前面一样采用极坐标形式，将圆周分为8个部分，代表8个方向，颜色越深代表风级越高，最后结果如下所示：</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104632825.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595989602612"></p>
<blockquote>
<p>分析可以发现未来14天东南风、西南风所占主要风向，风级最高达到了5级，最低的西风平均风级也有3级。</p>
</blockquote>
</li>
</ul>
<h3 id="未来14天气候分布饼图"><a href="#未来14天气候分布饼图" class="headerlink" title="未来14天气候分布饼图"></a>未来14天气候分布饼图</h3><ul>
<li><p>统计未来14天的气候，并求每个气候的总天数，最后将各个气候的饼图绘制出来，结果如下所示：</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104644115.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595989712833"></p>
<blockquote>
<p>分析可以发现未来14天气候基本是“雨”、“阴转雨”和“阵雨”，下雨的天数较多,结合前面的气温分布图可以看出在第8-9天气温高温下降，可以推测当天下雨，导致气温下降。</p>
</blockquote>
</li>
</ul>
<h2 id="3-结论"><a href="#3-结论" class="headerlink" title="3.结论"></a>3.结论</h2><ul>
<li>1.首先根据爬取的温湿度数据进行的分析，温度从早上低到中午高再到晚上低，湿度和温度的趋势相反，通过相关系数发现温度和湿度有强烈的负相关关系，经查阅资料发现因为随着温度升高水蒸汽蒸发加剧，空气中水分降低湿度降低。当然，湿度同时受气压和雨水的影响，下雨湿度会明显增高。</li>
<li>2.经查阅资料空气质量不仅跟工厂、汽车等排放的烟气、废气等有关，更为重要的是与气象因素有关。由于昼夜温差明显变化，当地面温度高于高空温度时，空气上升，污染物易被带到高空扩散；当地面温度低于一定高度的温度时，天空形成逆温层，它像一个大盖子一样压在地面上空，使地表空气中各种污染物不易扩散。一般在晚间和清晨影响较大，而当太阳出来后，地面迅速升温，逆温层就会逐渐消散，于是污染空气也就扩散了。</li>
<li>3.风是由气压在水平方向分布的不均匀导致的。风受大气环流、地形、水域等不同因素的综合影响，表现形式多种多样，如季风、地方性的海陆风、山谷风等，一天的风向也有不同的变化，根据未来14天的风向雷达图可以发现未来所有风向基本都有涉及，并且没有特别的某个风向，原因可能是近期没有降水和气文变化不大，导致风向也没有太大的变化规律。</li>
<li>4.天气是指某一个地区距离地表较近的大气层在短时间内的具体状态。跟某瞬时内大气中各种气象要素分布的综合表现。根据未来14天的天气和温度变化可以大致推断出某个时间的气候，天气和温度之间也是有联系的，</li>
</ul>
<h2 id="4-代码框架"><a href="#4-代码框架" class="headerlink" title="4.代码框架"></a>4.代码框架</h2><ul>
<li><p>代码主要分为<code>weather.py</code>：对中国天气网进行爬取天气数据并保存csv文件；<code>data1_analysis.py</code>：对当天的天气信息进行可视化处理；<code>data14_analysis.py</code>：对未来14天的天气信息进行可视化处理。下面是代码的结构图：</p>
<p><img src="https://img-blog.csdnimg.cn/20200729104657532.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1595989921430"></p>
</li>
</ul>
<h2 id="附源代码"><a href="#附源代码" class="headerlink" title="附源代码"></a>附源代码</h2><p>weather.py</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># weather.py</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">from</span> bs4 <span class="keyword">import</span> BeautifulSoup</span><br><span class="line"><span class="keyword">import</span> csv</span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">getHTMLtext</span>(<span class="params">url</span>):</span>     </span><br><span class="line">	<span class="string">&quot;&quot;&quot;请求获得网页内容&quot;&quot;&quot;</span></span><br><span class="line">	<span class="keyword">try</span>:         </span><br><span class="line">		r = requests.get(url, timeout = <span class="number">30</span>)         </span><br><span class="line">		r.raise_for_status()         </span><br><span class="line">		r.encoding = r.apparent_encoding         </span><br><span class="line">		<span class="built_in">print</span>(<span class="string">&quot;成功访问&quot;</span>)         </span><br><span class="line">		<span class="keyword">return</span> r.text     </span><br><span class="line">	<span class="keyword">except</span>:         </span><br><span class="line">		<span class="built_in">print</span>(<span class="string">&quot;访问错误&quot;</span>)         </span><br><span class="line">		<span class="keyword">return</span><span class="string">&quot; &quot;</span> </span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_content</span>(<span class="params">html</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;处理得到有用信息保存数据文件&quot;&quot;&quot;</span></span><br><span class="line">	final = []  							 <span class="comment"># 初始化一个列表保存数据</span></span><br><span class="line">	bs = BeautifulSoup(html, <span class="string">&quot;html.parser&quot;</span>)  <span class="comment"># 创建BeautifulSoup对象</span></span><br><span class="line">	body = bs.body</span><br><span class="line">	data = body.find(<span class="string">&#x27;div&#x27;</span>, &#123;<span class="string">&#x27;id&#x27;</span>: <span class="string">&#x27;7d&#x27;</span>&#125;)    <span class="comment"># 找到div标签且id = 7d</span></span><br><span class="line">	<span class="comment"># 下面爬取当天的数据</span></span><br><span class="line">	data2 = body.find_all(<span class="string">&#x27;div&#x27;</span>,&#123;<span class="string">&#x27;class&#x27;</span>:<span class="string">&#x27;left-div&#x27;</span>&#125;)</span><br><span class="line">	text = data2[<span class="number">2</span>].find(<span class="string">&#x27;script&#x27;</span>).string	 </span><br><span class="line">	text = text[text.index(<span class="string">&#x27;=&#x27;</span>)+<span class="number">1</span> :-<span class="number">2</span>]		 <span class="comment"># 移除改var data=将其变为json数据</span></span><br><span class="line">	jd = json.loads(text)</span><br><span class="line">	dayone = jd[<span class="string">&#x27;od&#x27;</span>][<span class="string">&#x27;od2&#x27;</span>]				 <span class="comment"># 找到当天的数据</span></span><br><span class="line">	final_day = []						     <span class="comment"># 存放当天的数据</span></span><br><span class="line">	count = <span class="number">0</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> dayone:</span><br><span class="line">		temp = []</span><br><span class="line">		<span class="keyword">if</span> count &lt;=<span class="number">23</span>:</span><br><span class="line">			temp.append(i[<span class="string">&#x27;od21&#x27;</span>])				 <span class="comment"># 添加时间</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od22&#x27;</span>])				 <span class="comment"># 添加当前时刻温度</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od24&#x27;</span>])				 <span class="comment"># 添加当前时刻风力方向</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od25&#x27;</span>])				 <span class="comment"># 添加当前时刻风级</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od26&#x27;</span>])				 <span class="comment"># 添加当前时刻降水量</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od27&#x27;</span>])				 <span class="comment"># 添加当前时刻相对湿度</span></span><br><span class="line">			temp.append(i[<span class="string">&#x27;od28&#x27;</span>])				 <span class="comment"># 添加当前时刻控制质量</span></span><br><span class="line">			<span class="comment">#print(temp)</span></span><br><span class="line">			final_day.append(temp)</span><br><span class="line">		count = count +<span class="number">1</span></span><br><span class="line">	<span class="comment"># 下面爬取7天的数据	</span></span><br><span class="line">	ul = data.find(<span class="string">&#x27;ul&#x27;</span>)					 <span class="comment"># 找到所有的ul标签</span></span><br><span class="line">	li = ul.find_all(<span class="string">&#x27;li&#x27;</span>)					 <span class="comment"># 找到左右的li标签</span></span><br><span class="line">	i = <span class="number">0</span>  			<span class="comment"># 控制爬取的天数</span></span><br><span class="line">	<span class="keyword">for</span> day <span class="keyword">in</span> li:  						 	<span class="comment"># 遍历找到的每一个li</span></span><br><span class="line">	    <span class="keyword">if</span> i &lt; <span class="number">7</span> <span class="keyword">and</span> i &gt; <span class="number">0</span>:</span><br><span class="line">	        temp = []  						 	<span class="comment"># 临时存放每天的数据</span></span><br><span class="line">	        date = day.find(<span class="string">&#x27;h1&#x27;</span>).string  	 	<span class="comment"># 得到日期</span></span><br><span class="line">	        date = date[<span class="number">0</span>:date.index(<span class="string">&#x27;日&#x27;</span>)]  	<span class="comment"># 取出日期号</span></span><br><span class="line">	        temp.append(date)				        </span><br><span class="line">	        inf = day.find_all(<span class="string">&#x27;p&#x27;</span>)  		 	<span class="comment"># 找出li下面的p标签,提取第一个p标签的值，即天气</span></span><br><span class="line">	        temp.append(inf[<span class="number">0</span>].string)</span><br><span class="line"></span><br><span class="line">	        tem_low = inf[<span class="number">1</span>].find(<span class="string">&#x27;i&#x27;</span>).string  	<span class="comment"># 找到最低气温</span></span><br><span class="line"></span><br><span class="line">	        <span class="keyword">if</span> inf[<span class="number">1</span>].find(<span class="string">&#x27;span&#x27;</span>) <span class="keyword">is</span> <span class="literal">None</span>:  	<span class="comment"># 天气预报可能没有最高气温</span></span><br><span class="line">	            tem_high = <span class="literal">None</span></span><br><span class="line">	        <span class="keyword">else</span>:</span><br><span class="line">	            tem_high = inf[<span class="number">1</span>].find(<span class="string">&#x27;span&#x27;</span>).string  <span class="comment"># 找到最高气温</span></span><br><span class="line">	        temp.append(tem_low[:-<span class="number">1</span>])</span><br><span class="line">	        <span class="keyword">if</span> tem_high[-<span class="number">1</span>] == <span class="string">&#x27;℃&#x27;</span>:</span><br><span class="line">	        	temp.append(tem_high[:-<span class="number">1</span>])</span><br><span class="line">	        <span class="keyword">else</span>:</span><br><span class="line">	        	temp.append(tem_high)</span><br><span class="line"></span><br><span class="line">	        wind = inf[<span class="number">2</span>].find_all(<span class="string">&#x27;span&#x27;</span>)		<span class="comment"># 找到风向</span></span><br><span class="line">	        <span class="keyword">for</span> j <span class="keyword">in</span> wind:</span><br><span class="line">	        	temp.append(j[<span class="string">&#x27;title&#x27;</span>])</span><br><span class="line"></span><br><span class="line">	        wind_scale = inf[<span class="number">2</span>].find(<span class="string">&#x27;i&#x27;</span>).string <span class="comment"># 找到风级</span></span><br><span class="line">	        index1 = wind_scale.index(<span class="string">&#x27;级&#x27;</span>)</span><br><span class="line">	       	temp.append(<span class="built_in">int</span>(wind_scale[index1-<span class="number">1</span>:index1]))</span><br><span class="line">	        final.append(temp)</span><br><span class="line">	    i = i + <span class="number">1</span></span><br><span class="line">	<span class="keyword">return</span> final_day,final</span><br><span class="line">	<span class="comment">#print(final)    </span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_content2</span>(<span class="params">html</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;处理得到有用信息保存数据文件&quot;&quot;&quot;</span></span><br><span class="line">	final = []  							 						<span class="comment"># 初始化一个列表保存数据</span></span><br><span class="line">	bs = BeautifulSoup(html, <span class="string">&quot;html.parser&quot;</span>)  						<span class="comment"># 创建BeautifulSoup对象</span></span><br><span class="line">	body = bs.body</span><br><span class="line">	data = body.find(<span class="string">&#x27;div&#x27;</span>, &#123;<span class="string">&#x27;id&#x27;</span>: <span class="string">&#x27;15d&#x27;</span>&#125;)    						<span class="comment"># 找到div标签且id = 15d</span></span><br><span class="line">	ul = data.find(<span class="string">&#x27;ul&#x27;</span>)					 						<span class="comment"># 找到所有的ul标签</span></span><br><span class="line">	li = ul.find_all(<span class="string">&#x27;li&#x27;</span>)					 						<span class="comment"># 找到左右的li标签</span></span><br><span class="line">	final = []</span><br><span class="line">	i = <span class="number">0</span>  															<span class="comment"># 控制爬取的天数</span></span><br><span class="line">	<span class="keyword">for</span> day <span class="keyword">in</span> li:  						 						<span class="comment"># 遍历找到的每一个li</span></span><br><span class="line">	    <span class="keyword">if</span> i &lt; <span class="number">8</span>:</span><br><span class="line">	        temp = []  						 						<span class="comment"># 临时存放每天的数据</span></span><br><span class="line">	        date = day.find(<span class="string">&#x27;span&#x27;</span>,&#123;<span class="string">&#x27;class&#x27;</span>:<span class="string">&#x27;time&#x27;</span>&#125;).string  		<span class="comment"># 得到日期</span></span><br><span class="line">	        date = date[date.index(<span class="string">&#x27;（&#x27;</span>)+<span class="number">1</span>:-<span class="number">2</span>]  						<span class="comment"># 取出日期号</span></span><br><span class="line">	        temp.append(date)		</span><br><span class="line">	       	weather = day.find(<span class="string">&#x27;span&#x27;</span>,&#123;<span class="string">&#x27;class&#x27;</span>:<span class="string">&#x27;wea&#x27;</span>&#125;).string  		<span class="comment"># 找到天气</span></span><br><span class="line">	        temp.append(weather)</span><br><span class="line">	        tem = day.find(<span class="string">&#x27;span&#x27;</span>,&#123;<span class="string">&#x27;class&#x27;</span>:<span class="string">&#x27;tem&#x27;</span>&#125;).text		  		<span class="comment"># 找到温度</span></span><br><span class="line">	        temp.append(tem[tem.index(<span class="string">&#x27;/&#x27;</span>)+<span class="number">1</span>:-<span class="number">1</span>])					<span class="comment"># 找到最低气温</span></span><br><span class="line">	        temp.append(tem[:tem.index(<span class="string">&#x27;/&#x27;</span>)-<span class="number">1</span>]) 					<span class="comment"># 找到最高气温</span></span><br><span class="line">	        wind = day.find(<span class="string">&#x27;span&#x27;</span>,&#123;<span class="string">&#x27;class&#x27;</span>:<span class="string">&#x27;wind&#x27;</span>&#125;).string  		<span class="comment"># 找到风向</span></span><br><span class="line">	        <span class="keyword">if</span> <span class="string">&#x27;转&#x27;</span> <span class="keyword">in</span> wind:											<span class="comment"># 如果有风向变化</span></span><br><span class="line">	        	temp.append(wind[:wind.index(<span class="string">&#x27;转&#x27;</span>)])</span><br><span class="line">	        	temp.append(wind[wind.index(<span class="string">&#x27;转&#x27;</span>)+<span class="number">1</span>:])</span><br><span class="line">	        <span class="keyword">else</span>:													<span class="comment"># 如果没有风向变化，前后风向一致</span></span><br><span class="line">	        	temp.append(wind)</span><br><span class="line">	        	temp.append(wind)</span><br><span class="line">	        wind_scale = day.find(<span class="string">&#x27;span&#x27;</span>,&#123;<span class="string">&#x27;class&#x27;</span>:<span class="string">&#x27;wind1&#x27;</span>&#125;).string  		<span class="comment"># 找到风级</span></span><br><span class="line">	        index1 = wind_scale.index(<span class="string">&#x27;级&#x27;</span>)</span><br><span class="line">	       	temp.append(<span class="built_in">int</span>(wind_scale[index1-<span class="number">1</span>:index1]))</span><br><span class="line">	        	</span><br><span class="line">	        final.append(temp)</span><br><span class="line">	<span class="keyword">return</span> final</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">write_to_csv</span>(<span class="params">file_name, data, day=<span class="number">14</span></span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;保存为csv文件&quot;&quot;&quot;</span></span><br><span class="line">	<span class="keyword">with</span> <span class="built_in">open</span>(file_name, <span class="string">&#x27;a&#x27;</span>, errors=<span class="string">&#x27;ignore&#x27;</span>, newline=<span class="string">&#x27;&#x27;</span>) <span class="keyword">as</span> f:</span><br><span class="line">		<span class="keyword">if</span> day == <span class="number">14</span>:</span><br><span class="line">			header = [<span class="string">&#x27;日期&#x27;</span>,<span class="string">&#x27;天气&#x27;</span>,<span class="string">&#x27;最低气温&#x27;</span>,<span class="string">&#x27;最高气温&#x27;</span>,<span class="string">&#x27;风向1&#x27;</span>,<span class="string">&#x27;风向2&#x27;</span>,<span class="string">&#x27;风级&#x27;</span>]</span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			header = [<span class="string">&#x27;小时&#x27;</span>,<span class="string">&#x27;温度&#x27;</span>,<span class="string">&#x27;风力方向&#x27;</span>,<span class="string">&#x27;风级&#x27;</span>,<span class="string">&#x27;降水量&#x27;</span>,<span class="string">&#x27;相对湿度&#x27;</span>,<span class="string">&#x27;空气质量&#x27;</span>]</span><br><span class="line">		f_csv = csv.writer(f)</span><br><span class="line">		f_csv.writerow(header)</span><br><span class="line">		f_csv.writerows(data)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span>():</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;主函数&quot;&quot;&quot;</span></span><br><span class="line">	<span class="built_in">print</span>(<span class="string">&quot;Weather test&quot;</span>)</span><br><span class="line">	<span class="comment"># 珠海</span></span><br><span class="line">	url1 = <span class="string">&#x27;http://www.weather.com.cn/weather/101280701.shtml&#x27;</span>    <span class="comment"># 7天天气中国天气网</span></span><br><span class="line">	url2 = <span class="string">&#x27;http://www.weather.com.cn/weather15d/101280701.shtml&#x27;</span> <span class="comment"># 8-15天天气中国天气网</span></span><br><span class="line">	</span><br><span class="line">	html1 = getHTMLtext(url1)</span><br><span class="line">	data1, data1_7 = get_content(html1)		<span class="comment"># 获得1-7天和当天的数据</span></span><br><span class="line"></span><br><span class="line">	html2 = getHTMLtext(url2)</span><br><span class="line">	data8_14 = get_content2(html2)			<span class="comment"># 获得8-14天数据</span></span><br><span class="line">	data14 = data1_7 + data8_14</span><br><span class="line">	<span class="comment">#print(data)</span></span><br><span class="line">	write_to_csv(<span class="string">&#x27;weather14.csv&#x27;</span>,data14,<span class="number">14</span>)	<span class="comment"># 保存为csv文件</span></span><br><span class="line">	write_to_csv(<span class="string">&#x27;weather1.csv&#x27;</span>,data1,<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">	main()</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>data1_analysis.py:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># data1_analysis.py</span></span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"><span class="keyword">import</span> math</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">tem_curve</span>(<span class="params">data</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;温度曲线绘制&quot;&quot;&quot;</span></span><br><span class="line">	hour = <span class="built_in">list</span>(data[<span class="string">&#x27;小时&#x27;</span>])</span><br><span class="line">	tem = <span class="built_in">list</span>(data[<span class="string">&#x27;温度&#x27;</span>])</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">24</span>):</span><br><span class="line">		<span class="keyword">if</span> math.isnan(tem[i]) == <span class="literal">True</span>:</span><br><span class="line">			tem[i] = tem[i-<span class="number">1</span>]</span><br><span class="line">	tem_ave = <span class="built_in">sum</span>(tem)/<span class="number">24</span>					<span class="comment"># 求平均温度 </span></span><br><span class="line">	tem_max = <span class="built_in">max</span>(tem)				</span><br><span class="line">	tem_max_hour = hour[tem.index(tem_max)]	<span class="comment"># 求最高温度</span></span><br><span class="line">	tem_min = <span class="built_in">min</span>(tem)</span><br><span class="line">	tem_min_hour = hour[tem.index(tem_min)]	<span class="comment"># 求最低温度</span></span><br><span class="line">	x = []</span><br><span class="line">	y = []</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="number">24</span>):</span><br><span class="line">		x.append(i)</span><br><span class="line">		y.append(tem[hour.index(i)])</span><br><span class="line">	plt.figure(<span class="number">1</span>)</span><br><span class="line">	plt.plot(x,y,color=<span class="string">&#x27;red&#x27;</span>,label=<span class="string">&#x27;温度&#x27;</span>)							<span class="comment"># 画出温度曲线</span></span><br><span class="line">	plt.scatter(x,y,color=<span class="string">&#x27;red&#x27;</span>)			<span class="comment"># 点出每个时刻的温度点</span></span><br><span class="line">	plt.plot([<span class="number">0</span>, <span class="number">24</span>], [tem_ave, tem_ave], c=<span class="string">&#x27;blue&#x27;</span>, linestyle=<span class="string">&#x27;--&#x27;</span>,label=<span class="string">&#x27;平均温度&#x27;</span>) 	<span class="comment"># 画出平均温度虚线</span></span><br><span class="line">	plt.text(tem_max_hour+<span class="number">0.15</span>, tem_max+<span class="number">0.15</span>, <span class="built_in">str</span>(tem_max), ha=<span class="string">&#x27;center&#x27;</span>, va=<span class="string">&#x27;bottom&#x27;</span>, fontsize=<span class="number">10.5</span>)  <span class="comment"># 标出最高温度</span></span><br><span class="line">	plt.text(tem_min_hour+<span class="number">0.15</span>, tem_min+<span class="number">0.15</span>, <span class="built_in">str</span>(tem_min), ha=<span class="string">&#x27;center&#x27;</span>, va=<span class="string">&#x27;bottom&#x27;</span>, fontsize=<span class="number">10.5</span>)  <span class="comment"># 标出最低温度</span></span><br><span class="line">	plt.xticks(x)</span><br><span class="line">	plt.legend()</span><br><span class="line">	plt.title(<span class="string">&#x27;一天温度变化曲线图&#x27;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&#x27;时间/h&#x27;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&#x27;摄氏度/℃&#x27;</span>)</span><br><span class="line">	plt.show()</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">hum_curve</span>(<span class="params">data</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;相对湿度曲线绘制&quot;&quot;&quot;</span></span><br><span class="line">	hour = <span class="built_in">list</span>(data[<span class="string">&#x27;小时&#x27;</span>])</span><br><span class="line">	hum = <span class="built_in">list</span>(data[<span class="string">&#x27;相对湿度&#x27;</span>])</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">24</span>):</span><br><span class="line">		<span class="keyword">if</span> math.isnan(hum[i]) == <span class="literal">True</span>:</span><br><span class="line">			hum[i] = hum[i-<span class="number">1</span>]</span><br><span class="line">	hum_ave = <span class="built_in">sum</span>(hum)/<span class="number">24</span>					<span class="comment"># 求平均相对湿度 </span></span><br><span class="line">	hum_max = <span class="built_in">max</span>(hum)				</span><br><span class="line">	hum_max_hour = hour[hum.index(hum_max)]	<span class="comment"># 求最高相对湿度</span></span><br><span class="line">	hum_min = <span class="built_in">min</span>(hum)</span><br><span class="line">	hum_min_hour = hour[hum.index(hum_min)]	<span class="comment"># 求最低相对湿度</span></span><br><span class="line">	x = []</span><br><span class="line">	y = []</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="number">24</span>):</span><br><span class="line">		x.append(i)</span><br><span class="line">		y.append(hum[hour.index(i)])</span><br><span class="line">	plt.figure(<span class="number">2</span>)</span><br><span class="line">	plt.plot(x,y,color=<span class="string">&#x27;blue&#x27;</span>,label=<span class="string">&#x27;相对湿度&#x27;</span>)							<span class="comment"># 画出相对湿度曲线</span></span><br><span class="line">	plt.scatter(x,y,color=<span class="string">&#x27;blue&#x27;</span>)			<span class="comment"># 点出每个时刻的相对湿度</span></span><br><span class="line">	plt.plot([<span class="number">0</span>, <span class="number">24</span>], [hum_ave, hum_ave], c=<span class="string">&#x27;red&#x27;</span>, linestyle=<span class="string">&#x27;--&#x27;</span>,label=<span class="string">&#x27;平均相对湿度&#x27;</span>) 	<span class="comment"># 画出平均相对湿度虚线</span></span><br><span class="line">	plt.text(hum_max_hour+<span class="number">0.15</span>, hum_max+<span class="number">0.15</span>, <span class="built_in">str</span>(hum_max), ha=<span class="string">&#x27;center&#x27;</span>, va=<span class="string">&#x27;bottom&#x27;</span>, fontsize=<span class="number">10.5</span>)  <span class="comment"># 标出最高相对湿度</span></span><br><span class="line">	plt.text(hum_min_hour+<span class="number">0.15</span>, hum_min+<span class="number">0.15</span>, <span class="built_in">str</span>(hum_min), ha=<span class="string">&#x27;center&#x27;</span>, va=<span class="string">&#x27;bottom&#x27;</span>, fontsize=<span class="number">10.5</span>)  <span class="comment"># 标出最低相对湿度</span></span><br><span class="line">	plt.xticks(x)</span><br><span class="line">	plt.legend()</span><br><span class="line">	plt.title(<span class="string">&#x27;一天相对湿度变化曲线图&#x27;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&#x27;时间/h&#x27;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&#x27;百分比/%&#x27;</span>)</span><br><span class="line">	plt.show()</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">air_curve</span>(<span class="params">data</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;空气质量曲线绘制&quot;&quot;&quot;</span></span><br><span class="line">	hour = <span class="built_in">list</span>(data[<span class="string">&#x27;小时&#x27;</span>])</span><br><span class="line">	air = <span class="built_in">list</span>(data[<span class="string">&#x27;空气质量&#x27;</span>])</span><br><span class="line">	<span class="built_in">print</span>(<span class="built_in">type</span>(air[<span class="number">0</span>]))</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">24</span>):</span><br><span class="line">		<span class="keyword">if</span> math.isnan(air[i]) == <span class="literal">True</span>:</span><br><span class="line">			air[i] = air[i-<span class="number">1</span>]</span><br><span class="line">	air_ave = <span class="built_in">sum</span>(air)/<span class="number">24</span>					<span class="comment"># 求平均空气质量 </span></span><br><span class="line">	air_max = <span class="built_in">max</span>(air)				</span><br><span class="line">	air_max_hour = hour[air.index(air_max)]	<span class="comment"># 求最高空气质量</span></span><br><span class="line">	air_min = <span class="built_in">min</span>(air)</span><br><span class="line">	air_min_hour = hour[air.index(air_min)]	<span class="comment"># 求最低空气质量</span></span><br><span class="line">	x = []</span><br><span class="line">	y = []</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="number">24</span>):</span><br><span class="line">		x.append(i)</span><br><span class="line">		y.append(air[hour.index(i)])</span><br><span class="line">	plt.figure(<span class="number">3</span>)</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">24</span>):</span><br><span class="line">		<span class="keyword">if</span> y[i] &lt;= <span class="number">50</span>:</span><br><span class="line">			plt.bar(x[i],y[i],color=<span class="string">&#x27;lightgreen&#x27;</span>,width=<span class="number">0.7</span>)  <span class="comment"># 1等级</span></span><br><span class="line">		<span class="keyword">elif</span> y[i] &lt;= <span class="number">100</span>:</span><br><span class="line">			plt.bar(x[i],y[i],color=<span class="string">&#x27;wheat&#x27;</span>,width=<span class="number">0.7</span>)		 <span class="comment"># 2等级</span></span><br><span class="line">		<span class="keyword">elif</span> y[i] &lt;= <span class="number">150</span>:</span><br><span class="line">			plt.bar(x[i],y[i],color=<span class="string">&#x27;orange&#x27;</span>,width=<span class="number">0.7</span>)		 <span class="comment"># 3等级</span></span><br><span class="line">		<span class="keyword">elif</span> y[i] &lt;= <span class="number">200</span>:</span><br><span class="line">			plt.bar(x[i],y[i],color=<span class="string">&#x27;orangered&#x27;</span>,width=<span class="number">0.7</span>)	 <span class="comment"># 4等级</span></span><br><span class="line">		<span class="keyword">elif</span> y[i] &lt;= <span class="number">300</span>:</span><br><span class="line">			plt.bar(x[i],y[i],color=<span class="string">&#x27;darkviolet&#x27;</span>,width=<span class="number">0.7</span>)	 <span class="comment"># 5等级</span></span><br><span class="line">		<span class="keyword">elif</span> y[i] &gt; <span class="number">300</span>:</span><br><span class="line">			plt.bar(x[i],y[i],color=<span class="string">&#x27;maroon&#x27;</span>,width=<span class="number">0.7</span>)		 <span class="comment"># 6等级</span></span><br><span class="line">	plt.plot([<span class="number">0</span>, <span class="number">24</span>], [air_ave, air_ave], c=<span class="string">&#x27;black&#x27;</span>, linestyle=<span class="string">&#x27;--&#x27;</span>) 	<span class="comment"># 画出平均空气质量虚线</span></span><br><span class="line">	plt.text(air_max_hour+<span class="number">0.15</span>, air_max+<span class="number">0.15</span>, <span class="built_in">str</span>(air_max), ha=<span class="string">&#x27;center&#x27;</span>, va=<span class="string">&#x27;bottom&#x27;</span>, fontsize=<span class="number">10.5</span>)  <span class="comment"># 标出最高空气质量</span></span><br><span class="line">	plt.text(air_min_hour+<span class="number">0.15</span>, air_min+<span class="number">0.15</span>, <span class="built_in">str</span>(air_min), ha=<span class="string">&#x27;center&#x27;</span>, va=<span class="string">&#x27;bottom&#x27;</span>, fontsize=<span class="number">10.5</span>)  <span class="comment"># 标出最低空气质量</span></span><br><span class="line">	plt.xticks(x)</span><br><span class="line">	plt.title(<span class="string">&#x27;一天空气质量变化曲线图&#x27;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&#x27;时间/h&#x27;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&#x27;空气质量指数AQI&#x27;</span>)</span><br><span class="line">	plt.show()</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wind_radar</span>(<span class="params">data</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;风向雷达图&quot;&quot;&quot;</span></span><br><span class="line">	wind = <span class="built_in">list</span>(data[<span class="string">&#x27;风力方向&#x27;</span>])</span><br><span class="line">	wind_speed = <span class="built_in">list</span>(data[<span class="string">&#x27;风级&#x27;</span>])</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">24</span>):</span><br><span class="line">		<span class="keyword">if</span> wind[i] == <span class="string">&quot;北风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">90</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;南风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">270</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;西风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">180</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;东风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">360</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;东北风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">45</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;西北风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">135</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;西南风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">225</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;东南风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">315</span></span><br><span class="line">	degs = np.arange(<span class="number">45</span>,<span class="number">361</span>,<span class="number">45</span>)</span><br><span class="line">	temp = []</span><br><span class="line">	<span class="keyword">for</span> deg <span class="keyword">in</span> degs:</span><br><span class="line">		speed = []</span><br><span class="line">		<span class="comment"># 获取 wind_deg 在指定范围的风速平均值数据</span></span><br><span class="line">		<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">24</span>):</span><br><span class="line">			<span class="keyword">if</span> wind[i] == deg:</span><br><span class="line">				speed.append(wind_speed[i])</span><br><span class="line">		<span class="keyword">if</span> <span class="built_in">len</span>(speed) == <span class="number">0</span>:</span><br><span class="line">			temp.append(<span class="number">0</span>)</span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			temp.append(<span class="built_in">sum</span>(speed)/<span class="built_in">len</span>(speed))</span><br><span class="line">	<span class="built_in">print</span>(temp)</span><br><span class="line">	N = <span class="number">8</span></span><br><span class="line">	theta = np.arange(<span class="number">0.</span>+np.pi/<span class="number">8</span>,<span class="number">2</span>*np.pi+np.pi/<span class="number">8</span>,<span class="number">2</span>*np.pi/<span class="number">8</span>)</span><br><span class="line">	<span class="comment"># 数据极径</span></span><br><span class="line">	radii = np.array(temp)</span><br><span class="line">	<span class="comment"># 绘制极区图坐标系</span></span><br><span class="line">	plt.axes(polar=<span class="literal">True</span>)</span><br><span class="line">	<span class="comment"># 定义每个扇区的RGB值（R,G,B），x越大，对应的颜色越接近蓝色</span></span><br><span class="line">	colors = [(<span class="number">1</span>-x/<span class="built_in">max</span>(temp), <span class="number">1</span>-x/<span class="built_in">max</span>(temp),<span class="number">0.6</span>) <span class="keyword">for</span> x <span class="keyword">in</span> radii]</span><br><span class="line">	plt.bar(theta,radii,width=(<span class="number">2</span>*np.pi/N),bottom=<span class="number">0.0</span>,color=colors)</span><br><span class="line">	plt.title(<span class="string">&#x27;一天风级图&#x27;</span>,x=<span class="number">0.2</span>,fontsize=<span class="number">20</span>)</span><br><span class="line">	plt.show()</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">calc_corr</span>(<span class="params">a, b</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;计算相关系数&quot;&quot;&quot;</span></span><br><span class="line">	a_avg = <span class="built_in">sum</span>(a)/<span class="built_in">len</span>(a)</span><br><span class="line">	b_avg = <span class="built_in">sum</span>(b)/<span class="built_in">len</span>(b)</span><br><span class="line">	cov_ab = <span class="built_in">sum</span>([(x - a_avg)*(y - b_avg) <span class="keyword">for</span> x,y <span class="keyword">in</span> <span class="built_in">zip</span>(a, b)])</span><br><span class="line">	sq = math.sqrt(<span class="built_in">sum</span>([(x - a_avg)**<span class="number">2</span> <span class="keyword">for</span> x <span class="keyword">in</span> a])*<span class="built_in">sum</span>([(x - b_avg)**<span class="number">2</span> <span class="keyword">for</span> x <span class="keyword">in</span> b])) </span><br><span class="line">	corr_factor = cov_ab/sq</span><br><span class="line">	<span class="keyword">return</span> corr_factor</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">corr_tem_hum</span>(<span class="params">data</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;温湿度相关性分析&quot;&quot;&quot;</span></span><br><span class="line">	tem = data[<span class="string">&#x27;温度&#x27;</span>]</span><br><span class="line">	hum = data[<span class="string">&#x27;相对湿度&#x27;</span>]</span><br><span class="line">	plt.scatter(tem,hum,color=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line">	plt.title(<span class="string">&quot;温湿度相关性分析图&quot;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&quot;温度/℃&quot;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&quot;相对湿度/%&quot;</span>)</span><br><span class="line">	plt.text(<span class="number">20</span>,<span class="number">40</span>,<span class="string">&quot;相关系数为：&quot;</span>+<span class="built_in">str</span>(calc_corr(tem,hum)),fontdict=&#123;<span class="string">&#x27;size&#x27;</span>:<span class="string">&#x27;10&#x27;</span>,<span class="string">&#x27;color&#x27;</span>:<span class="string">&#x27;red&#x27;</span>&#125;)</span><br><span class="line">	plt.show()</span><br><span class="line">	<span class="built_in">print</span>(<span class="string">&quot;相关系数为：&quot;</span>+<span class="built_in">str</span>(calc_corr(tem,hum)))</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span>():</span></span><br><span class="line">	plt.rcParams[<span class="string">&#x27;font.sans-serif&#x27;</span>]=[<span class="string">&#x27;SimHei&#x27;</span>]	<span class="comment"># 解决中文显示问题</span></span><br><span class="line">	plt.rcParams[<span class="string">&#x27;axes.unicode_minus&#x27;</span>] = <span class="literal">False</span>  <span class="comment"># 解决负号显示问题</span></span><br><span class="line">	data1 = pd.read_csv(<span class="string">&#x27;weather1.csv&#x27;</span>,encoding=<span class="string">&#x27;gb2312&#x27;</span>)</span><br><span class="line">	<span class="built_in">print</span>(data1)</span><br><span class="line">	tem_curve(data1)</span><br><span class="line">	hum_curve(data1)</span><br><span class="line">	air_curve(data1)</span><br><span class="line">	wind_radar(data1)</span><br><span class="line">	corr_tem_hum(data1)</span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">	main()</span><br></pre></td></tr></table></figure>
<p>data14_analysis.py:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># data14_analysis.py</span></span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"><span class="keyword">import</span> math</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">tem_curve</span>(<span class="params">data</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;温度曲线绘制&quot;&quot;&quot;</span></span><br><span class="line">	date = <span class="built_in">list</span>(data[<span class="string">&#x27;日期&#x27;</span>])</span><br><span class="line">	tem_low = <span class="built_in">list</span>(data[<span class="string">&#x27;最低气温&#x27;</span>])</span><br><span class="line">	tem_high = <span class="built_in">list</span>(data[<span class="string">&#x27;最高气温&#x27;</span>])</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">14</span>):</span><br><span class="line">		<span class="keyword">if</span> math.isnan(tem_low[i]) == <span class="literal">True</span>:</span><br><span class="line">			tem_low[i] = tem_low[i-<span class="number">1</span>]</span><br><span class="line">		<span class="keyword">if</span> math.isnan(tem_high[i]) == <span class="literal">True</span>:</span><br><span class="line">			tem_high[i] = tem_high[i-<span class="number">1</span>]</span><br><span class="line"></span><br><span class="line">	tem_high_ave = <span class="built_in">sum</span>(tem_high)/<span class="number">14</span>					<span class="comment"># 求平均高温 </span></span><br><span class="line">	tem_low_ave = <span class="built_in">sum</span>(tem_low)/<span class="number">14</span>					<span class="comment"># 求平均低温 </span></span><br><span class="line">	</span><br><span class="line">	tem_max = <span class="built_in">max</span>(tem_high)				</span><br><span class="line">	tem_max_date = tem_high.index(tem_max)			<span class="comment"># 求最高温度</span></span><br><span class="line">	tem_min = <span class="built_in">min</span>(tem_low)</span><br><span class="line">	tem_min_date = tem_low.index(tem_min)			<span class="comment"># 求最低温度</span></span><br><span class="line"></span><br><span class="line">	x = <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">15</span>)</span><br><span class="line">	plt.figure(<span class="number">1</span>)</span><br><span class="line">	plt.plot(x,tem_high,color=<span class="string">&#x27;red&#x27;</span>,label=<span class="string">&#x27;高温&#x27;</span>)				<span class="comment"># 画出高温度曲线</span></span><br><span class="line">	plt.scatter(x,tem_high,color=<span class="string">&#x27;red&#x27;</span>)					<span class="comment"># 点出每个时刻的温度点</span></span><br><span class="line">	plt.plot(x,tem_low,color=<span class="string">&#x27;blue&#x27;</span>,label=<span class="string">&#x27;低温&#x27;</span>)				<span class="comment"># 画出低温度曲线</span></span><br><span class="line">	plt.scatter(x,tem_low,color=<span class="string">&#x27;blue&#x27;</span>)					<span class="comment"># 点出每个时刻的温度点</span></span><br><span class="line">	</span><br><span class="line">	plt.plot([<span class="number">1</span>, <span class="number">15</span>], [tem_high_ave, tem_high_ave], c=<span class="string">&#x27;black&#x27;</span>, linestyle=<span class="string">&#x27;--&#x27;</span>) 	<span class="comment"># 画出平均温度虚线</span></span><br><span class="line">	plt.plot([<span class="number">1</span>, <span class="number">15</span>], [tem_low_ave, tem_low_ave], c=<span class="string">&#x27;black&#x27;</span>, linestyle=<span class="string">&#x27;--&#x27;</span>) 	<span class="comment"># 画出平均温度虚线</span></span><br><span class="line">	plt.legend()</span><br><span class="line">	plt.text(tem_max_date+<span class="number">0.15</span>, tem_max+<span class="number">0.15</span>, <span class="built_in">str</span>(tem_max), ha=<span class="string">&#x27;center&#x27;</span>, va=<span class="string">&#x27;bottom&#x27;</span>, fontsize=<span class="number">10.5</span>)  <span class="comment"># 标出最高温度</span></span><br><span class="line">	plt.text(tem_min_date+<span class="number">0.15</span>, tem_min+<span class="number">0.15</span>, <span class="built_in">str</span>(tem_min), ha=<span class="string">&#x27;center&#x27;</span>, va=<span class="string">&#x27;bottom&#x27;</span>, fontsize=<span class="number">10.5</span>)  <span class="comment"># 标出最低温度</span></span><br><span class="line">	plt.xticks(x)</span><br><span class="line">	plt.title(<span class="string">&#x27;未来14天高温低温变化曲线图&#x27;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&#x27;未来天数/天&#x27;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&#x27;摄氏度/℃&#x27;</span>)</span><br><span class="line">	plt.show()</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">change_wind</span>(<span class="params">wind</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;改变风向&quot;&quot;&quot;</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">14</span>):</span><br><span class="line">		<span class="keyword">if</span> wind[i] == <span class="string">&quot;北风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">90</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;南风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">270</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;西风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">180</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;东风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">360</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;东北风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">45</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;西北风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">135</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;西南风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">225</span></span><br><span class="line">		<span class="keyword">elif</span> wind[i] == <span class="string">&quot;东南风&quot;</span>:</span><br><span class="line">			wind[i] = <span class="number">315</span></span><br><span class="line">	<span class="keyword">return</span> wind</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wind_radar</span>(<span class="params">data</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;风向雷达图&quot;&quot;&quot;</span></span><br><span class="line">	wind1 = <span class="built_in">list</span>(data[<span class="string">&#x27;风向1&#x27;</span>])</span><br><span class="line">	wind2 = <span class="built_in">list</span>(data[<span class="string">&#x27;风向2&#x27;</span>])</span><br><span class="line">	wind_speed = <span class="built_in">list</span>(data[<span class="string">&#x27;风级&#x27;</span>])</span><br><span class="line">	wind1 = change_wind(wind1)</span><br><span class="line">	wind2 = change_wind(wind2)</span><br><span class="line">	</span><br><span class="line">	degs = np.arange(<span class="number">45</span>,<span class="number">361</span>,<span class="number">45</span>)</span><br><span class="line">	temp = []</span><br><span class="line">	<span class="keyword">for</span> deg <span class="keyword">in</span> degs:</span><br><span class="line">		speed = []</span><br><span class="line">		<span class="comment"># 获取 wind_deg 在指定范围的风速平均值数据</span></span><br><span class="line">		<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">14</span>):</span><br><span class="line">			<span class="keyword">if</span> wind1[i] == deg:</span><br><span class="line">				speed.append(wind_speed[i])</span><br><span class="line">			<span class="keyword">if</span> wind2[i] == deg:</span><br><span class="line">				speed.append(wind_speed[i])</span><br><span class="line">		<span class="keyword">if</span> <span class="built_in">len</span>(speed) == <span class="number">0</span>:</span><br><span class="line">			temp.append(<span class="number">0</span>)</span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			temp.append(<span class="built_in">sum</span>(speed)/<span class="built_in">len</span>(speed))</span><br><span class="line">	<span class="built_in">print</span>(temp)</span><br><span class="line">	N = <span class="number">8</span></span><br><span class="line">	theta = np.arange(<span class="number">0.</span>+np.pi/<span class="number">8</span>,<span class="number">2</span>*np.pi+np.pi/<span class="number">8</span>,<span class="number">2</span>*np.pi/<span class="number">8</span>)</span><br><span class="line">	<span class="comment"># 数据极径</span></span><br><span class="line">	radii = np.array(temp)</span><br><span class="line">	<span class="comment"># 绘制极区图坐标系</span></span><br><span class="line">	plt.axes(polar=<span class="literal">True</span>)</span><br><span class="line">	<span class="comment"># 定义每个扇区的RGB值（R,G,B），x越大，对应的颜色越接近蓝色</span></span><br><span class="line">	colors = [(<span class="number">1</span>-x/<span class="built_in">max</span>(temp), <span class="number">1</span>-x/<span class="built_in">max</span>(temp),<span class="number">0.6</span>) <span class="keyword">for</span> x <span class="keyword">in</span> radii]</span><br><span class="line">	plt.bar(theta,radii,width=(<span class="number">2</span>*np.pi/N),bottom=<span class="number">0.0</span>,color=colors)</span><br><span class="line">	plt.title(<span class="string">&#x27;未来14天风级图&#x27;</span>,x=<span class="number">0.2</span>,fontsize=<span class="number">20</span>)</span><br><span class="line">	plt.show()</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">weather_pie</span>(<span class="params">data</span>):</span></span><br><span class="line">	<span class="string">&quot;&quot;&quot;绘制天气饼图&quot;&quot;&quot;</span></span><br><span class="line">	weather = <span class="built_in">list</span>(data[<span class="string">&#x27;天气&#x27;</span>])</span><br><span class="line">	dic_wea = &#123; &#125;</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="number">14</span>):</span><br><span class="line">		<span class="keyword">if</span> weather[i] <span class="keyword">in</span> dic_wea.keys():</span><br><span class="line">			dic_wea[weather[i]] += <span class="number">1</span></span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			dic_wea[weather[i]] = <span class="number">1</span></span><br><span class="line">	<span class="built_in">print</span>(dic_wea)</span><br><span class="line">	explode=[<span class="number">0.01</span>]*<span class="built_in">len</span>(dic_wea.keys())</span><br><span class="line">	color = [<span class="string">&#x27;lightskyblue&#x27;</span>,<span class="string">&#x27;silver&#x27;</span>,<span class="string">&#x27;yellow&#x27;</span>,<span class="string">&#x27;salmon&#x27;</span>,<span class="string">&#x27;grey&#x27;</span>,<span class="string">&#x27;lime&#x27;</span>,<span class="string">&#x27;gold&#x27;</span>,<span class="string">&#x27;red&#x27;</span>,<span class="string">&#x27;green&#x27;</span>,<span class="string">&#x27;pink&#x27;</span>]</span><br><span class="line">	plt.pie(dic_wea.values(),explode=explode,labels=dic_wea.keys(),autopct=<span class="string">&#x27;%1.1f%%&#x27;</span>,colors=color)</span><br><span class="line">	plt.title(<span class="string">&#x27;未来14天气候分布饼图&#x27;</span>)</span><br><span class="line">	plt.show()</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span>():</span></span><br><span class="line">	plt.rcParams[<span class="string">&#x27;font.sans-serif&#x27;</span>]=[<span class="string">&#x27;SimHei&#x27;</span>]	<span class="comment"># 解决中文显示问题</span></span><br><span class="line">	plt.rcParams[<span class="string">&#x27;axes.unicode_minus&#x27;</span>] = <span class="literal">False</span>  <span class="comment"># 解决负号显示问题</span></span><br><span class="line">	data14 = pd.read_csv(<span class="string">&#x27;weather14.csv&#x27;</span>,encoding=<span class="string">&#x27;gb2312&#x27;</span>)</span><br><span class="line">	<span class="built_in">print</span>(data14)</span><br><span class="line">	tem_curve(data14)</span><br><span class="line">	wind_radar(data14)</span><br><span class="line">	weather_pie(data14)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">	main()</span><br></pre></td></tr></table></figure>

        </div>

        
            <section class="post-copyright">
                
                    <p class="copyright-item">
                        <span>Author:</span>
                        <span><a href="/about/">WD</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>Permalink:</span>
                        <span><a href="https://did321.gitee.io/2020/07/29/Python%E7%88%AC%E5%8F%96%E5%A4%A9%E6%B0%94%E6%95%B0%E6%8D%AE%E5%8F%8A%E5%8F%AF%E8%A7%86%E5%8C%96%E5%88%86%E6%9E%90/">https://did321.gitee.io/2020/07/29/Python%E7%88%AC%E5%8F%96%E5%A4%A9%E6%B0%94%E6%95%B0%E6%8D%AE%E5%8F%8A%E5%8F%AF%E8%A7%86%E5%8C%96%E5%88%86%E6%9E%90/</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>License:</span>
                        <span>Copyright (c) 2022 <a target="_blank" rel="noopener" href="http://creativecommons.org/licenses/by-nc/4.0/">CC-BY-NC-4.0</a> LICENSE</span>
                    </p>
                
                
                     <p class="copyright-item">
                         <span>Slogan:</span>
                         <span><a href="#">The blog is my giant.</a></span>
                     </p>
                

            </section>
        
        <section class="post-tags">
            <div>
                <span>Tag(s):</span>
                <span class="tag">
                    
                    
                        <a href="/tags/python/"># python</a>
                    
                        <a href="/tags/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/"># 数据分析</a>
                    
                        
                </span>
            </div>
            <div>
                <a href="javascript:window.history.back();">back</a>
                <span>· </span>
                <a href="/">home</a>
            </div>
        </section>
        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/2020/07/30/MathJax-Test/">MathJax Test</a>
            
            
            <a class="next" rel="next" href="/2020/07/17/Forest%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E5%8F%8A%E5%8F%AF%E8%A7%86%E5%8C%96/">Forest数据分析及可视化</a>
            
        </section>
        <br>
        <br>
    
    <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
    <div id="vcomments"></div>
    <script>
        new Valine({
    el: '#vcomments' ,

    appId: 'JvFy3ebVLo2rUYgHaMweJyXX-MdYXbMMI',
    appKey: 'TCFxfjDAM8UmERPEgYXJmT40',
    serverURLs: 'https://JvFy3ebV.api.lncldglobal.com', 
    placeholder: '----评论区----留下你的评论，作者会定期回复！在昵称处填写QQ号可自动获取邮箱和QQ头像（保护QQ邮箱隐私）',
    enableQQ: true,
    requiredFields: ['nick'],
});
    </script>

    </article>
</div>

        </div>
        <footer id="footer" class="footer">
    <div class="copyright">
        <span>© WD | Powered by <a href="https://hexo.io" target="_blank">Hexo</a> & <a href="https://github.com/Siricee/hexo-theme-Chic" target="_blank">Chic</a></span>
    </div>
</footer>

    </div>
</body>

</html>
